package jframe.base.action;

import java.io.PrintWriter;
import java.io.Serializable;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jframe.common.JsonHelper;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @描述:<p> </p>
 *
 * @作者: 叶平平(yepp)
 *
 * @时间: 2011-7-30 上午12:29:48
 */
@SuppressWarnings("serial")
public class BaseAction  extends ActionSupport implements ServletRequestAware, ServletResponseAware, Serializable{

	public HttpServletRequest request;
	public HttpServletResponse response;
	
	public JsonHelper jsonHelper;
	
	public Integer limit;
	
	public Integer start;
	
	
	/**
	 * @描述:<p>获取Session  </p>
	 *
	 * @作者:  叶平平(yepp)
	 *
	 * @时间:  2011-8-26 下午10:37:03
	 *
	 * @修改历史: <p>修改时间、修改人、修改原因/说明</p>
	 *
	 * @return
	 */
	public Map<String,Object> getSession(){
		return ActionContext.getContext().getSession();
	}

	/**
	 * @描述:<p>获得servlet上下文  </p>
	 *
	 * @作者:  叶平平(yepp)
	 *
	 * @时间:  2011-8-26 下午10:43:04
	 *
	 * @修改历史: <p>修改时间、修改人、修改原因/说明</p>
	 *
	 * @return
	 */
	public ServletContext getServletContext(){
		return ServletActionContext.getServletContext();
	}
	
	/**
	 * @描述:<p>  </p>
	 *
	 * @作者:  叶平平(yepp)
	 *
	 * @时间:  2011-8-26 下午10:44:48
	 *
	 * @修改历史: <p>修改时间、修改人、修改原因/说明</p>
	 *
	 * @return
	 */
	public ActionContext getContext(){
		return ActionContext.getContext();
	}
	
	/**
	 * @描述:<p>获取路径  </p>
	 *
	 * @作者:  叶平平(yepp)
	 *
	 * @时间:  2011-8-26 下午10:45:46
	 *
	 * @修改历史: <p>修改时间、修改人、修改原因/说明</p>
	 *
	 * @param path
	 * @return
	 */
	public String getRealyPath(String path){
		return getServletContext().getRealPath(path);
	}
	
	
	
	
	
	
	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public HttpServletResponse getResponse() {
		return response;
	}

	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}

	public JsonHelper getJsonHelper() {
		return jsonHelper;
	}

	public void setJsonHelper(JsonHelper jsonHelper) {
		this.jsonHelper = jsonHelper;
	}

	/* (non-Javadoc)
	 * @see org.apache.struts2.interceptor.ServletRequestAware#setServletRequest(javax.servlet.http.HttpServletRequest)
	 */
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
		
	}

	/* (non-Javadoc)
	 * @see org.apache.struts2.interceptor.ServletResponseAware#setServletResponse(javax.servlet.http.HttpServletResponse)
	 */
	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
		
	}
	
	/**
	 * @描述:<p>输出字符串  </p>
	 *
	 * @作者:  叶平平(yepp)
	 *
	 * @时间:  2011-11-3 下午11:51:20
	 *
	 * @修改历史: <p>修改时间、修改人、修改原因/说明</p>
	 *
	 * @param str
	 */
	public void outString(String str){
		try {
			PrintWriter out = getResponse().getWriter();
			out.write(str);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void outXMLString(String xmlStr){
		getResponse().setContentType("applicaton/xml;charset=UTF-8");
		outString(xmlStr);
	}
	public void outJsonString(String jsonStr){
		getResponse().setContentType("applicaton/json;charset=UTF-8");
		outString(jsonStr);
	}
	public Integer getLimit() {
		return limit;
	}

	public void setLimit(Integer limit) {
		this.limit = limit;
	}

	public Integer getStart() {
		return start;
	}

	public void setStart(Integer start) {
		this.start = start;
	}

	
	
	
}
